<template>
    <div id="patch">
        <ReturnPage />
        <div class="mt20">
            <!-- 分发记录列表 -->
            <div class="tp_box mt20">
                <el-form ref="ruleForm"
                         label-width="150px"
                         :model="ruleForm">
                    <el-form-item label="远程主机地址"
                                  prop="hostIp">
                        <el-input v-model="ruleForm.hostIp"
                                  placeholder="请输入远程主机地址"></el-input>
                    </el-form-item>
                    <el-form-item label="配置文件名称"
                                  prop="configName">
                        <el-input v-model="ruleForm.configName"
                                  placeholder="请输入配置文件名称"></el-input>
                    </el-form-item>
                    <el-form-item label="配置文件地址"
                                  prop="configDir">
                        <el-input v-model="ruleForm.configDir"
                                  placeholder="请输入配置文件地址"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="用户名"
                                  prop="username">
                        <el-input v-model="ruleForm.username"
                                  placeholder="请输入用户名"></el-input>
                    </el-form-item>
                    <el-form-item prop="password"
                                  label="密码">
                        <el-input v-model="ruleForm.password"
                                  type="password"
                                  placeholder="密码">
                        </el-input>
                    </el-form-item> -->
                    <el-form-item label="文件内容">
                        <el-input type="textarea"
                                  v-model="content"
                                  :rows="20"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary"
                                   @click="loadfile('ruleForm')">加载文件</el-button>
                        <el-button type="success"
                                   @click="UpdateConfiguration()">更新配置</el-button>
                        <el-button type="info"
                                   @click="resetting()">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
            </el-form>
            </el-dialog>
        </div>
    </div>
</template>

<script>
    //接口
    import {
        addloadfile_Api, //
        editloadfile_Api,//删除
    } from "@/api/automated/host.js";

    export default {
        data () {
            return {
                ruleForm: {
                    hostIp: null,
                    configDir: null,
                    configName: null,
                    hostId: this.$route.query.hostid,
                    username: null,
                    password: null
                },
                content: ''
            };
        },
        methods: {
            //加载文件
            loadfile () {
                addloadfile_Api(this.ruleForm).then(res => {
                    console.log(res)
                    if (res) {
                        this.content = res
                        this.$message.success("加载文件成功");
                    } else {
                        this.$$message.success("加载文件失败");
                    }
                })
            },
            //更新配置
            UpdateConfiguration () {
                this.ruleForm.fileContent = this.content
                console.log(this.ruleForm)
                editloadfile_Api(this.ruleForm).then(res => {
                    if (res.code == 200) {
                        this.$message.success("更新成功");

                    } else {
                        this.$message.success("更新失败");
                    }
                })
            },
            //重置
            resetting () {
                this.ruleForm = {}
            }
        },
        created () {
            console.log(this.$route.query.hostid)
        },
    };
</script>

